package com.ruoyi.management.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.management.dao.mapper.DbDayConverter;
import com.ruoyi.management.dao.mapper.DbDayMapper;
import com.ruoyi.management.pojo.dto.DbDayDto;
import com.ruoyi.management.pojo.po.DbDayPo;
import com.ruoyi.management.pojo.vo.DbDayVo;
import com.ruoyi.management.service.DbDayService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * 电表日用量服务实现类
 */
@Service
public class DbDayServiceImpl implements DbDayService {

    @Autowired
    private DbDayMapper dbDayMapper;

    /**
     * 获取电表日用量数据
     *
     * @param dbDayDto 参数
     * @return 数据
     */
    @Override
    public List<DbDayVo> selectDbDay(DbDayDto dbDayDto) {
        DbDayPo dbDayPo = DbDayConverter.INSTANCE.toDO(dbDayDto);
        QueryWrapper<DbDayPo> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda()
                .eq(StringUtils.isNotEmpty(dbDayPo.getDbbh()), DbDayPo::getDbbh, dbDayPo.getDbbh())
                .between(DbDayPo::getTimestamp, dbDayPo.getStartTime(), dbDayPo.getEndTime())
                .orderByAsc(DbDayPo::getTimestamp);
        return DbDayConverter.INSTANCE.toVOList(dbDayMapper.selectList(queryWrapper));
    }
}
